<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="yh.core.funcs.person.data.YHPerson" %>
<%@ page import="yh.core.global.YHConst" %>
<%@ include file="/public/header.jsp"%>
<% 
 String sNoOperate = request.getParameter("noOperate");
 boolean noOperate = false;
 if (!"".equals(sNoOperate) && sNoOperate != null) {
   noOperate = true;
 } 
 String type = request.getParameter("type");
 if(type == null || "".equals(type)){
   type = "1|2";
 }
 YHPerson loginUser = (YHPerson)request.getSession().getAttribute(YHConst.LOGIN_USER);
 String flowId = request.getParameter("flowId");  
 String sortId = request.getParameter("sortId");
  String opFlag = request.getParameter("opFlag");
 if (sortId == null) {
   sortId = "";
 }
 if (flowId == null || "".equals(flowId)) {
   flowId = "0";
 }
 String skin = request.getParameter("skin");
 String skinJs = "messages";
 if (skin != null && !"".equals(skin)) {
   skinJs = "messages_" + skin;
 } else {
   skin = "";
 }
 %>
 

<html>
	<head>
		<title>工作办理</title>
	</head>
<script type="text/javascript">
var type = <%=type%>;
var loginUserId = <%=loginUser.getSeqId()%>;
var sortId = "<%=sortId%>";
var flowType = "<%=flowId%>";
var flowId = "<%=flowId%>";
var noOperate = <%=noOperate%>;
var opFlag = <%=opFlag%>;
var skin = "<%=skin %>";
if(type != 3){
    par = "flowId=" + flowId+"&typeStr=" + type + "&sort=";
  }else{
    par = "flowId=" + flowId+"&typeStr=" + type + "&opFlag=" + opFlag + "&sort=";
  }
		$(function(){
			 $("#runId").keypress(function(e) { 
	    	// 回车键事件 
	     	  if(e.which == 13) { 
	     		 doSearch();
	       		} 
	   		}); 
			$('#type_id').combobox({  
        		url:'<%=contextPath %>/yh/core/funcs/workflow/act/YHFlowTypeAct/getFlowTypeJson3.act?sortId=' + sortId,  
       			valueField:'seqId',  
        		textField:'flowName',
        		onChange:function(){
        			doSearch();
        		}
   			});  
			$("#table").datagrid({
				title:"我的工作",
				iconCls:'icon-edit',
				loadMsg:'正在加载数据，请稍后......',
				url:'<%=contextPath %>/yh/core/funcs/workflow/act/YHMyWorkAct/getNewMyWorkList.act',
				queryParams: {
						flowId:flowId,
						typeStr:type,
						opFlag:opFlag
				},
                singleSelect:true,                             
				rownumbers:true,
				nowrap:false,
				fitColumns:true,
				idField:'id',
				frozenColumns:[[
				    {title:'编号',field:'seq_id',hidden:true}
				]],
				columns:[[
					{title:'流水号',field:'runId',width:100,align:'center'},
					{title:'时间',field:'prcs_time',width:100,align:'center'},
					{title:'流程名称',field:'flowName',width:100,align:'center'},
					{title:'工作文号',field:'runName',width:100,align:'center',formatter:function(value,rowDate,rowIndex){
						return "<a onclick=\"formView2("+rowDate.runId+","+rowDate.flowId+","+rowDate.prcsId+","+rowDate.flowPrcs+")\"  href=\"javascript:;\">"+rowDate.runName+"</a>";
						}
					},
					{title:'发起人',field:'userName',width:100,align:'center'},
					{title:'步骤',field:'flowPrcs',width:100,align:'center',formatter:function(value,rowDate,rowIndex){
						return "<a onclick=\"flowView("+rowDate.runId+","+rowDate.flowId+",'','','')\"  href=\"javascript:;\">第"+rowDate.flowPrcs+"步:"+rowDate.prcsName+"</a>";
						}
					},
					{title:'整个流程状态',field:'state',width:100,align:'center'},
					{title:'操作',field:'read_time',width:100,align:'center',formatter:function(value,rowDate,rowIndex){
					 var par = "runId=" + rowDate.runId + "&flowId=" + rowDate.flowId + "&prcsId=" + rowDate.prcsId + "&flowPrcs=" + rowDate.flowPrcs + "&sortId=" + sortId + "&skin=" + skin;
					 var  operate="<a href=\"#\" onclick=\"javascript:opration("+rowDate.runId+");\">查看</a>&nbsp;&nbsp;";
						if (rowDate.opFlag == 1 && rowDate.calBackPriv && rowDate.state != "已结束") {
					      operate += "<a href='javascript:' onclick='callBack(\""+ par +"\")'>收回</a>&nbsp;&nbsp;";
					    }
					    if (rowDate.isHaveDelPriv) {
					      operate += "&nbsp;&nbsp;<a href='javascript:' onclick='deleteRun("+ rowDate.runId +")'>删除</a> " ;
					    }
						return operate;
						}
					},
				]],
				
				pageSize:10,
				pageList : [10,50,100],  
				pagination:true,
				toolbar:'#tb',
				onLoadSuccess:function(rtJson){
					if(rtJson.rtState== '1')
					{
						$.messager.alert('提示',rtJson.rtMsrg);
					}
				}
			});
			
		});
		function deleteRun(runId) {
		 jQuery.messager.confirm('确认','确定删除该步骤？',function(msg){
				if(msg){
			    var url = contextPath+'/yh/core/funcs/workflow/act/YHMyWorkAct/delRun.act';
			    			jQuery.ajax({
								type:'POST',
								url:url,
								data:"runId=" + runId,
								dataType:"json",
								success:function(rtJson){
									if(rtJson.rtState == '0'){
										 alert(rtJson.rtMsrg) ;
										$("#table").datagrid("reload");
									}
									else{
									alert('提示：',rtJson.rtMsrg);
									}
								}
							});
			  }
			});
		  
       }
		function callBack(par){
			 jQuery.messager.confirm('确认','下一步骤尚未接收时可收回至本步骤重新办理，确认要收回吗？',function(msg){
				if(msg){
			    var url = contextPath+'/yh/core/funcs/workflow/act/YHMyWorkAct/callBack.act';
			    			jQuery.ajax({
								type:'POST',
								url:url,
								data:par,
								dataType:"json",
								success:function(rtJson){
									if(rtJson.rtState == '0'){
										warningInfo(rtJson.rtMsrg);
										$("#table").datagrid("reload");
									}
									else{
									jQuery.messager.alert('提示：',rtJson.rtMsrg);
									}
								}
							});
			  }
			});
	 }
		function opration(runId){
			jQuery.ajax({
				type:'POST',
				url:'<%=contextPath %>/springMVC/group/getBusinessView?flow_run_id='+runId,
				success:function(rtJson){
					if(rtJson.rtState == '0'){
						openDialogResize(rtJson.rtData.business_view,1000,800);
					}
					else{
						jQuery.messager.alert('提示：',rtJson.rtMsrg);
					}
				}
			});
		}
          
    /**
 * 实际流程图

 * @param runId
 * @param flowId
 * @param title
 * @return
 */
function flowView(runId , flowId , title , sortId , skin) {
  var url = contextPath + "/core/funcs/workflow/flowrun/list/flowview/index.jsp?runId="+runId+"&flowId="+flowId;
  if (sortId) {
    url += "&sortId=" + sortId; 
  }
  if (skin) {
    url += "&skin=" + skin; 
  }
  myleft=(screen.availWidth-800)/2;
  window.open(url,runId,"status=0,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,width=950,height=400,left="+myleft+",top=100");
}
/**
 * 打印表单2
 * @param runId
 * @param flowId
 * @return
 */
function formView2(runId , flowId,prcsId,flowPrcs) {
  var url = contextPath + "/core/funcs/workflow/flowrun/list/print/index.jsp?runId="+runId+"&flowId="+flowId+"&prcsId="+prcsId+"&flowPrcs="+flowPrcs;
  window.open(url ,"","status=0,toolbar=no,menubar=no,width="+(screen.availWidth-12)+",height="+(screen.availHeight-38)+",location=no,scrollbars=yes,resizable=yes,left=0,top=0");
}	
		function rtCallBack(){
			$('#table').datagrid('reload');
		}

		function doSearch(){
			var type_id = $('#type_id').combobox('getValue');
			var runId=$('#runId').val();
			$('#table').datagrid('load',{
				flowId:type_id,
				typeStr:type,
				runId:runId
				});
		}
		
		
		
		
	</script>
	<body>
		<div id="smsManage" class="easyui-layout" data-options="fit:true">
			<div region="center"  style="padding:5px;">
			    	<div id="table" data-options="fit:true"></div>
			    	<div id="tb" style="padding:3px;height:auto">
<div>
   
流程选择：<select id="type_id" name="type_id" style="width:200px;" onchange="doSearch()"></select> &nbsp;&nbsp; 
流水号：<input id="runId" name="runId" style="width:120px" title="流水号"  placeholder="流水号 "/>&nbsp;&nbsp; 
								<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
						</div>
					</div>
		    </div>
		</div>
	</body>
</html>
